<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script>
            var nums1 = [1, 2, 2, 1, 3]
            var nums2 = [2, 2, 3, 2, 1, 3, 3, 1, 1, 2]
            var arr = [];
            var arr1 = [];
            arr = nums2.filter(function (cur, index) {
                //return ((arr.indexOf(cur)>=0)&&nums1.indexOf(cur)>=0)
                return nums1.indexOf(cur) !== -1
            })
            console.log(arr)
            //filter实现去重
            arr1 = arr.filter(function (cur, index) {
                //[2,2,1].indexOf(2)只会返回0，不会返回1.
                return arr.indexOf(cur) === index;
            })
            console.log(arr1b)

        // 
        // console.log(arr)
        //     function map(nums1,nums2) {
        //         var nums3 = []
        //         nums1.forEach(function (value, index, arr) {
        //             nums2.forEach(function (value1, index1, arr1) {
        //                 if ((value1 === value) && nums3.indexOf(value1) < 0)
        //                     nums3.push(value)
        //             })
        //         }) 
        //         console.log(nums3)   
        //     }
        //    map([4,9,5],[9,4,9,8,4])
        //    map([1,2,2,1],[2,2])

    </script>
</body>

</html>